<template>
  <div class="home">
    <el-table :data="infoList" style="width: 100%" border>
      <el-table-column label="提醒信息">
        <template #default="{ row }">
          <span style="color: red"> {{ row.name }}的库存只剩 {{ row.stock }}，请尽快补充！ </span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup lang="ts">
import { ElMessage } from 'element-plus'
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import myAxios from '../../axios/myAxios'

const router = useRouter()
const infoList = ref([])

const init = async () => {
  const data = await myAxios.get('/medicine/list')
  infoList.value = data.data.data.records.filter((item) => item.stock <= 10)
}

onMounted(() => {
  if (!localStorage.getItem('token')) {
    ElMessage.error('请先登录')
    router.push('/login')
    return
  }
  init()
})
</script>
